using System.IO;
using System.Xml.Serialization;

namespace SZipHandler
{
    public static class JobHandler
    {
        public static void SaveToXML<T>(T o, string filePath)
        {
            if (File.Exists(filePath))
                File.Delete(filePath);

            var fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
            var serializer = new XmlSerializer(typeof(T));
            serializer.Serialize(fs, o);
            fs.Close();
        }

        public static T LoadFromXML<T>(string filePath)
        {
            var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            var serializer = new XmlSerializer(typeof(T));
            var result = (T)serializer.Deserialize(fs);
            fs.Close();
            return result;
        }
    }
}